﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
    public partial class TakingRule
    {

        partial void MedicalName1_Changed()
        {
            if(this.MedicalName1 != null)
                this.MedicalName1 = this.MedicalName1.ToUpper().Trim();
        }

        partial void MedicalName2_Changed()
        {
            if (this.MedicalName2 != null)
                this.MedicalName2 = this.MedicalName2.ToUpper().Trim();
        }

        partial void MedicalName2_Validate(EntityValidationResultsBuilder results)
        {
            // results.AddPropertyError("<Error-Message>");
            if (MedicalName1 != null && MedicalName2 != null)
            {
                if (MedicalName1 == MedicalName2)
                    results.AddPropertyError("MedicalName1 cannot be same with MedicalName2");
                if (this.DataWorkspace.ApplicationData.TakingRules.Where(rules => rules.MedicalName1 == this.MedicalName1 &&
                    rules.MedicalName2 == this.MedicalName2 && rules.Id != this.Id).FirstOrDefault() != null)
                    results.AddPropertyError("Duplicated rules: " + this.MedicalName1 + " - " + this.MedicalName2);
            }
        }
    }
}
